home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
snpd9611.zip
/
DECOMPIL.TXT
< prev
next >
Wrap
Text File
|
1996-11-24
|
4KB
|
98 lines
.I 0 1
+++Date last modified: 18-Feb-1996
.D 1 1
.I 2 2
Question:
.I 18 1
decompiler designed to only work on code generated by, say, BC++ 4.52? This
.D 19 1
.I 44 81
run into problems where the original source had files with multiple functions
using static data and/or one or more functions calling one or more static
functions. A decompiler could make static data and/or functions global but
only at the expense or readability (which would already be unacceptable).
Also, remember that commercial applications often code the most difficult
or time-critical functions in assembler which could prove almost impossible
to decompile into a C equivalent.
Closely related to the issue of modularity is that of library code.
Consider the ubiquitous "Hello world" program. After compilation it contains
about 10 bytes of compiled source, about a dozen bytes of data, and anywhere
from 5-10K (depending on compiler, target, memory model, etc.) of start up
and library code. This is a great example since printf() also calls *lots* of
other library functions of its own! Once the decompiler has assigned names to
the dozen or so functions in its output, the fun starts when you have to
figure out which arbitrarily-named function is really printf() and which
other functions are library helper functions that it calls. The bottom line
here is that in order to do so, you'd have to know enough about writing C
libraries to be able to recognize the code for printf() when you see it.
Again, the situation with C++ would be orders of magnitude more complex
trying to make sense of the compiled code once the O-O structures and
relationships had been compiled into oblivion. Even if you take the simple
approach and decompile C++ into C, would anyone like to try and trace through
the source to figure out a cout call which adds another 7-10K of overhead
vis-a-vis a printf() call? I sure wouldn't!!!
So what do your have? For a small program, you'd wind up trying to decipher
what is mostly library source. For a large program, you'd wind up with either
1) one humonguous main(), or 2) lots of arbitrary single-function modules
from which all notions of static data and functions would have been lost
(contributing to a vast pool of global data), which would still include
decompiled source for all the library objects as well. In any scenario, is
any of this useful? Probably not.
While we've touched on the topic of library code, here's yet another reason
that C and C++ are particularly difficult to de-compile: macros.
For instance, if I have something like:
while (EOF != ( ch = getchar())) {
if (isupper(ch))
putchar(ch);
getchar, EOF, putchar and isupper are all typically macros, something like:
#define EOF -1
#define isupper(x) (__types[(unsigned char)x+1] && __UPPER)
#define getchar() (getc(stdin))
#define putchar(c) (putc((c),stdout)
#define getc(s) ((s)->__pos<(s)->__len? \
(s)->__buf[__pos++]: \
filbuf(s))
#define putc(c,s) ((s)->__pos<(s)->__len? \
(s)->__buf[__pos++]=(c): \
putbuf((s),(c)))
Finally, stdin and stdout are generally just items in an array of FILE
pointers something like:
FILE __iobuf[20];
FILE *stdin = __iobuf; // This part is done silently by the
FILE *stdout = __iobuf + 1; // compiler, without actual source code
FILE *stderr = __iobuf + 2;
Even if you just expand the macros and never actually compile the code at
all, you end up with something that's basically unreadable. However, this is
what actually gets fed to the compiler, so it's also absolute best you could
ever hope for from a perfect de-compiler.
C++ of course adds in-line functions and after an optimizer runs across
things, the code from the in-line function may well be mixed in with
surrounding code, making it nearly impossible to extract the function from
the code that calls it. There are only a few formats in use for vtables,
which would help in preserving virtual functions, but inline functions would
be lost, so you'd typically end up with hundreds of times that code would be
directly accessing variables in other classes.
.D 45 8
.I 63 4
A general purpose decompiler is the Holy Grail of tyro programmers.
[by Bob Stout & Jerry Coffin]